class AcePawn extends Pawn;

var DynamicLightEnvironmentComponent LightEnvironment;

var float LinkDistanceMax;
var float LinkCurrentDistanceMax;
var AcePawn LinkPawn;
var float LinkCurrentDistance;

enum eLinkType
{
	eLinkType_VARIABLE,
	eLinkType_FIX
};

var eLinkType LinkType;

event PostBeginPlay()
{
	local AcePawn temp_pawn;

	super.PostBeginPlay();

	LinkCurrentDistanceMax = LinkDistanceMax;

	foreach DynamicActors( class'AcePawn', temp_pawn )
	{
		if( temp_pawn != self )
		{
			LinkPawn = temp_pawn;
			LinkPawn.LinkPawn = self;
			break;
		}
	}
}

function Tick( float DeltaTime )
{
	local Color color_link;
	local float ratio_distance;

	super.Tick( DeltaTime );

	if( LinkPawn == none )
		return;

	LinkCurrentDistance = VSize2D( Location - LinkPawn.Location );

	if( LinkType == eLinkType_VARIABLE )
	{
		LinkCurrentDistanceMax = LinkDistanceMax;
	}

	if( LinkCurrentDistance <= LinkCurrentDistanceMax )
	{
		ratio_distance = fMin( LinkCurrentDistance/LinkCurrentDistanceMax, 1.0f );
	}
	else
	{
		ratio_distance = 1.0f;
		SetLocation( LinkPawn.Location + Normal(Location-LinkPawn.Location)*LinkCurrentDistanceMax ); 
	}

	color_link.B = 0;
	color_link.G = (1.0f-ratio_distance) * 255;
	color_link.R = ratio_distance * 255;

	//DrawDebugSphere( LinkLocation, LinkCurrentDistanceMax, 32, color_link.R, color_link.G, color_link.B, false );
	DrawDebugLine( LinkPawn.Location*Vect(1,1,0) + Vect(0,0,10), Location*Vect(1,1,0), color_link.R, color_link.G, color_link.B, false );
	//`log( "ratio_distance" @ ratio_distance );
}

DefaultProperties
{
	Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
		bSynthesizeSHLight=TRUE
		bIsCharacterLightEnvironment=TRUE
		bUseBooleanEnvironmentShadowing=FALSE
	End Object
	Components.Add(MyLightEnvironment)
	LightEnvironment=MyLightEnvironment	

	Begin Object Class=SkeletalMeshComponent Name=SkeletalMeshComponent0
		SkeletalMesh=SkeletalMesh'CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode'
		PhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
		AnimtreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
	End Object
	Mesh=SkeletalMeshComponent0
	Components.Add(SkeletalMeshComponent0)

	LinkDistanceMax = 500.0f

	LinkType = eLinkType_VARIABLE;

	bCanJump = false

	//MaxStepHeight = 0.1f;
}
